/* -*- Mode:Prolog; coding:ISO-8859-1; -*- */
:- ensure_loaded(['../prolog/score_tools']).
:- multifile solution_score/1, heuristic_score/4, termination/1, additional_prune/2.



%ACCURACY

solution_score(1) :-
bb_get_value(strategy, custom_accuracy_based), !.

heuristic_score(Solution, Evaluation, _Info, HS) :-
bb_get_value(strategy, custom_accuracy_based), !,        
        log('--------------------'),
        portray_list(Solution),
        %complexity(Solution, S),
        entailed_negatives(Evaluation, EN),
        entailed_positives(Evaluation, EP),
        number_negatives(Evaluation, Neg),
        number_positives(Evaluation, Pos),
        TruePositive is EP,
        TrueNegative is Neg - EN,
        ((Temp1 is (Pos + Neg), Temp1 = 0) -> Accuracy = 0 ; Accuracy is (TruePositive + TrueNegative) / (Pos + Neg)),
        HS is - Accuracy,
        log('Score:'), log((-Accuracy = -((TruePositive + TrueNegative) / (Pos + Neg)))),
        log('--------------------').

%Never terminates (use a timeout)
termination(_Solution) :-
        bb_get_value(strategy, custom_accuracy_based), !, fail.

additional_prune(_S, _Evaluation) :-
        bb_get_value(strategy, custom_accuracy_based), !.


%PROGOL STYLE AT LEAST ONE

solution_score(1) :-
bb_get_value(strategy, progolap), !.

heuristic_score(Solution, Evaluation, _Info, HS) :-
bb_get_value(strategy, progolap), !,        
        log('--------------------'),
        portray_list(Solution),
        complexity(Solution, S),
        number_negatives(Evaluation, Neg),
        entailed_negatives(Evaluation, EN),
        entailed_positives(Evaluation, EP),
        (EP > 0 -> 
         HS is -(EP - EN - S),
         log('Score:'), log((HS = -(EP - EN - S)))
        ;
         HS is -(0 - Neg - S),
         log('Score:'), log(('Entails 0 positives'))
         ),
        
        log('--------------------').

termination(_Solution) :-
        bb_get_value(strategy, progolap), !, fail.

additional_prune(_S, _Evaluation) :-
        bb_get_value(strategy, progolap), !.